import 'package:flutter/material.dart';

void showAlertDialogSafely(BuildContext? context, String message,
    [String? title, Icon? icon]) {
  if (context!=null && context.mounted) {
    showDialog(
        context: context,
        builder: (context) {
          final ThemeData themeData = Theme.of(context);
          return AlertDialog(
            content: ListBody(
              children: <Widget>[
                Row(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: <Widget>[
                    if (icon != null)
                      IconTheme(data: themeData.iconTheme, child: icon),
                    Expanded(
                      child: Padding(
                        padding: const EdgeInsets.symmetric(
                            vertical: 18.0, horizontal: 18.0),
                        child: Text(title ?? "提示"),
                      ),
                    ),
                  ],
                ),
                Text(message),
              ],
            ),
            actions: <Widget>[
              TextButton(
                child: const Text("确定"),
                onPressed: () {
                  Navigator.pop(context);
                },
              ),
            ],
            scrollable: true,
          );
        });
  }
}
